// Playground - noun: a place where people can play

import Cocoa


/*********************************************************************
 * The Swift Language Learning  Chapter 16: Optional Chain
 *********************************************************************/

class Person {
	var residence: Residence?
}

class Residence {
	var numberOfRooms = 1
}

let john = Person()

//let roomCount = john.residence!.numberOfRooms  force unwap error
let roomCount = john.residence?.numberOfRooms


john.residence = Residence()
//let rc = john.residence.numberOfRooms error
if let rc = john.residence?.numberOfRooms{
	rc
}
else {
	
}


/*********************************************************************
* The Swift Language Learning  Chapter 17: Type Casting
*********************************************************************/


var things = Any[]()

things.append(0)
things.append(0.0)
things.append(42)
things.append(3.14159)
things.append("hello")
things.append((3.0, 5.0))

things


for thing in things {
	switch thing {
	case 0 as Int:
		println("zero as an Int")
	case 0 as Double:
		println("zero as a Double")
	case let someInt as Int:
		println("an integer value of \(someInt)")
	case let someDouble as Double where someDouble > 0:
		println("a positive double value of \(someDouble)")
	case is Double:
		println("some other double value that I don't want to print")
	case let someString as String:
		println("a string value of \"\(someString)\"")
	case let (x, y) as (Double, Double):
		println("an (x, y) point at \(x), \(y)")
	default:
		println("something else")
	}
}


/*********************************************************************
* The Swift Language Learning  Chapter 18: Nested Types
*********************************************************************/

......











